package top.chengdongqing.mishop.auth

import com.fasterxml.jackson.annotation.JsonFormat
import top.chengdongqing.mishop.entities.User
import top.chengdongqing.mishop.enums.Gender
import top.chengdongqing.mishop.utils.DesensitizingUtils.desensitizeAccount
import java.util.Date

data class AuthVO(
    val id: Int,
    val name: String,
    val gender: Gender?,
    val avatarUrl: String,
    val phoneNumber: String,
    val emailAddress: String?,
    val token: Token
) {
    companion object {
        fun of(user: User, token: Token): AuthVO {
            return AuthVO(
                id = user.id,
                name = user.name,
                gender = user.gender,
                avatarUrl = user.avatarUrl,
                phoneNumber = desensitizeAccount(user.phoneNumber),
                emailAddress = user.emailAddress?.let { desensitizeAccount(it) },
                token = token
            )
        }
    }
}

data class Token(
    val accessToken: String,
    val refreshToken: String,
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    val expireIn: Date
)